home *** CD-ROM | disk | FTP | other *** search
/ Aminet 16 / Aminet 16 (1996)(GTI - Schatztruhe)[!][Dec 1996].iso / Tools / MUI / Developer / C / Examples / EnvBrowser.c < prev    next >
C/C++ Source or Header  |  1996-08-20  |  4KB  |  140 lines

  1. #include "demo.h"
  2.  
  3. #define ID_DISPLAY 1
  4. #define ID_EDIT    2
  5. #define ID_DELETE  3
  6. #define ID_SAVE    4
  7.  
  8. static Object * App       ; /* Application object       */
  9. static Object * WI_Browser; /* Window object            */
  10. static Object * BT_Edit   ; /* Edit Button object       */
  11. static Object * BT_Delete ; /* Delete Button object     */
  12. static Object * BT_Save   ; /* Save Button object       */
  13. static Object * LV_Vars   ; /* Env.Var. Listview object */
  14. static Object * LV_Show   ; /* Contents Listview object */
  15.  
  16. int main(int argc,char *argv[])
  17. {
  18.     static char buffer[2048];
  19.     char *var;
  20.     BOOL running = TRUE;
  21.     ULONG signal;
  22.  
  23.     init();
  24.  
  25.     App = ApplicationObject,
  26.         MUIA_Application_Title      , "EnvBrowser",
  27.         MUIA_Application_Version    , "$VER: EnvBrowser 17.6 (18.08.96)",
  28.         MUIA_Application_Copyright  , "©1992/93, Stefan Stuntz",
  29.         MUIA_Application_Author     , "Stefan Stuntz",
  30.         MUIA_Application_Description, "View environment variables.",
  31.         MUIA_Application_Base       , "ENVBROWSER",
  32.         SubWindow, WI_Browser = WindowObject,
  33.             MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  34.             MUIA_Window_Title, "Environment Browser",
  35.             WindowContents, VGroup,
  36.                 Child, HGroup,
  37.                     Child, LV_Vars = ListviewObject,
  38.                         MUIA_Listview_List, DirlistObject,
  39.                             InputListFrame,
  40.                             MUIA_Dirlist_Directory      , "env:",
  41.                             MUIA_Dirlist_FilterDrawers, TRUE,
  42.                             MUIA_List_Format          , "COL=0",
  43.                             End,
  44.                         End,
  45.                     Child, LV_Show = ListviewObject,
  46.                         MUIA_Listview_List, FloattextObject,
  47.                             ReadListFrame,
  48.                             MUIA_Font, MUIV_Font_Fixed,
  49.                             End,
  50.                         End,
  51.                     End,
  52.                 Child, HGroup, MUIA_Group_SameSize, TRUE,
  53.                     Child, BT_Edit   = SimpleButton("_Edit"  ),
  54.                     Child, BT_Delete = SimpleButton("_Delete"),
  55.                     Child, BT_Save   = SimpleButton("_Save"  ),
  56.                     End,
  57.                 End,
  58.             End,
  59.         End;
  60.  
  61.     if (!App) fail(App,"Failed to create Application.");
  62.  
  63.     DoMethod(WI_Browser,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,App,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  64.     DoMethod(LV_Vars   ,MUIM_Notify,MUIA_List_Active,MUIV_EveryTime,App,2,MUIM_Application_ReturnID,ID_DISPLAY);
  65.     DoMethod(LV_Vars   ,MUIM_Notify,MUIA_Listview_DoubleClick,TRUE,App,2,MUIM_Application_ReturnID,ID_EDIT);
  66.     DoMethod(BT_Delete ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_DELETE);
  67.     DoMethod(BT_Save   ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_SAVE  );
  68.     DoMethod(BT_Edit   ,MUIM_Notify,MUIA_Pressed,FALSE,App,2,MUIM_Application_ReturnID,ID_EDIT  );
  69.  
  70.     DoMethod(WI_Browser,MUIM_Window_SetCycleChain,LV_Vars,LV_Show,BT_Edit,BT_Delete,BT_Save,NULL);
  71.  
  72.     set(WI_Browser,MUIA_Window_Open,TRUE);
  73.  
  74.     while (running)
  75.     {
  76.         switch (DoMethod(App,MUIM_Application_Input,&signal))
  77.         {
  78.             case MUIV_Application_ReturnID_Quit:
  79.                 running = FALSE;
  80.                 break;
  81.  
  82.             case ID_DISPLAY:
  83.             {
  84.                 get(LV_Vars,MUIA_Dirlist_Path,&var);
  85.                 if (var && GetVar(var,buffer,sizeof(buffer),GVF_GLOBAL_ONLY|GVF_BINARY_VAR)!=-1)
  86.                     set(LV_Show,MUIA_Floattext_Text,buffer);
  87.                 else DisplayBeep(0);
  88.                 break;
  89.             }
  90.  
  91.             case ID_DELETE:
  92.             {
  93.                 get(LV_Vars,MUIA_Dirlist_Path,&var);
  94.                 if (var)
  95.                 {
  96.                     set(LV_Show,MUIA_Floattext_Text,NULL);
  97.                     DeleteFile(var);
  98.                     DoMethod(LV_Vars,MUIM_List_Remove,MUIV_List_Remove_Active);
  99.                 }
  100.                  else DisplayBeep(0);
  101.                 break;
  102.             }
  103.  
  104.             case ID_SAVE:
  105.             {
  106.                 get(LV_Vars,MUIA_Dirlist_Path,&var);
  107.                 if (var)
  108.                 {
  109.                     set(App,MUIA_Application_Sleep,TRUE);
  110.                     sprintf(buffer,"copy env:%s envarc:%s",FilePart(var),FilePart(var));
  111.                     Execute(buffer,0,0);
  112.                     set(App,MUIA_Application_Sleep,FALSE);
  113.                 }
  114.                 else DisplayBeep(0);
  115.                 break;
  116.             }
  117.  
  118.             case ID_EDIT:
  119.             {
  120.                 get(LV_Vars,MUIA_Dirlist_Path,&var);
  121.                 if (var)
  122.                 {
  123.                     set(App,MUIA_Application_Sleep,TRUE);
  124.                     sprintf(buffer,"ed -sticky \"%s\"",var);
  125.                     Execute(buffer,0,0);
  126.                     set(App,MUIA_Application_Sleep,FALSE);
  127.                     DoMethod(WI_Browser,MUIM_Window_ScreenToFront);
  128.                 }
  129.                 else DisplayBeep(0);
  130.                 break;
  131.             }
  132.         }
  133.  
  134.         if (running && signal)
  135.             Wait(signal);
  136.     }
  137.  
  138.     fail(App,NULL);
  139. }
  140.